package cn.maple.mq.transactionMessage;

import org.apache.rocketmq.spring.annotation.RocketMQTransactionListener;
import org.apache.rocketmq.spring.core.RocketMQLocalTransactionListener;
import org.apache.rocketmq.spring.core.RocketMQLocalTransactionState;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;

@Component
@RocketMQTransactionListener(txProducerGroup = "Transaction-message-group")
public class MyTransactionListener implements RocketMQLocalTransactionListener {
    @Override
    public RocketMQLocalTransactionState executeLocalTransaction(Message message, Object o) {
        System.out.println("+++++++++++++++++监听器成功+++++++++++++++");
        System.out.println(message.toString()+o);
        return RocketMQLocalTransactionState.COMMIT;
    }

    @Override
    public RocketMQLocalTransactionState checkLocalTransaction(Message message) {
        System.out.println("+++++++++++++++++监听器失败+++++++++++++++");
        System.out.println(message.toString());
        return RocketMQLocalTransactionState.ROLLBACK;
    }
}
